/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TestJPanel.java
 *
 * Created on 21 mai 2013, 16:51:41
 */

package Vue;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JTextField;
import javax.swing.GroupLayout;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.Font;
import javax.swing.JButton;

import controleur.GestionBDD;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 *
 * @author yannick.henriet
 */
public class IHM_connexion extends javax.swing.JPanel {
	private JTextField nom_textField;
	private JTextField id_textField;
	
    /** Creates new form TestJPanel */
    public IHM_connexion() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        
        nom_textField = new JTextField();
        nom_textField.setColumns(10);
        
        id_textField = new JTextField();
        id_textField.setColumns(10);
        
        JLabel lblNom = new JLabel("NOM");
        lblNom.setFont(new Font("Tahoma", Font.PLAIN, 17));
        
        JLabel lblId = new JLabel("ID");
        lblId.setFont(new Font("Tahoma", Font.PLAIN, 17));
        
        JLabel lblConnexion = new JLabel("CONNEXION");
        lblConnexion.setFont(new Font("Tahoma", Font.PLAIN, 22));
        
        JButton btnNewButton = new JButton("Valider");
        btnNewButton.addMouseListener(new MouseAdapter() {
        	@Override
        	public void mouseClicked(MouseEvent arg0) {
        		Control_IHM_user.getInstance().usrpoub2.setNom(nom_textField.getText());
        		Control_IHM_user.getInstance().usrpoub2.setId(Integer.parseInt(id_textField.getText()));
        		if ((GestionBDD.getInstance().Connexion(Integer.parseInt(id_textField.getText()), nom_textField.getText()))== 1)
        		{
        			//System.out.println(GestionBDD.getInstance().Connexion(Integer.parseInt(id_textField.getText()), nom_textField.getText()));
        			Control_IHM_user.getInstance().choixSelection("interface_user");
        			System.out.println("bon");
        		}
        		else
        		{
        			Control_IHM_user.getInstance().choixSelection("accueil");
        			System.out.println("mauvais");
        		}
        		
        	}
        });
        btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 14));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        layout.setHorizontalGroup(
        	layout.createParallelGroup(Alignment.TRAILING)
        		.addGroup(layout.createSequentialGroup()
        			.addGap(47)
        			.addGroup(layout.createParallelGroup(Alignment.TRAILING)
        				.addComponent(lblNom)
        				.addComponent(lblId))
        			.addGap(18)
        			.addGroup(layout.createParallelGroup(Alignment.LEADING, false)
        				.addComponent(id_textField, Alignment.TRAILING)
        				.addComponent(nom_textField, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE))
        			.addContainerGap(115, Short.MAX_VALUE))
        		.addGroup(layout.createSequentialGroup()
        			.addContainerGap(169, Short.MAX_VALUE)
        			.addComponent(lblConnexion)
        			.addGap(158))
        		.addGroup(layout.createSequentialGroup()
        			.addContainerGap(178, Short.MAX_VALUE)
        			.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)
        			.addGap(181))
        );
        layout.setVerticalGroup(
        	layout.createParallelGroup(Alignment.LEADING)
        		.addGroup(layout.createSequentialGroup()
        			.addGap(51)
        			.addComponent(lblConnexion)
        			.addGap(48)
        			.addGroup(layout.createParallelGroup(Alignment.BASELINE)
        				.addComponent(nom_textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
        				.addComponent(lblNom))
        			.addGap(18)
        			.addGroup(layout.createParallelGroup(Alignment.LEADING)
        				.addComponent(id_textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
        				.addComponent(lblId))
        			.addGap(29)
        			.addComponent(btnNewButton)
        			.addContainerGap(58, Short.MAX_VALUE))
        );
        this.setLayout(layout);
    }// </editor-fold>//GEN-END:initComponents
}
